import random


# 生成随机数
def generateRandomScores(num, min, max):
    scores = []
    while len(scores) < num:
        scores.append(random.randint(min, max))
    return scores


# 统计结果
def calculateScores(scores):
    scoresdic = {}
    for score in scores:
        if scoresdic.get(score):
            oldv = int(scoresdic[score])
            scoresdic[score] = oldv + 1
        else:
            scoresdic[score] = 1
    return scoresdic


# 统计结果(返回两个区间)
def calculateScoresDuring(scoresdic: dict) -> dict:
    sdic: dict = {"80~90": 0, "90~100": 0}
    for key in scoresdic.keys():
        if key < 90:
            sdic["80~90"] += scoresdic[key]
        else:
            sdic["90~100"] += scoresdic[key]
    return sdic


if __name__ == '__main__':
    num = generateRandomScores(20, 80, 100)
    scores = calculateScores(num)
    sdic = calculateScoresDuring(scores)
    print(scores)
    print(sdic)
